<template>
  <div class="app-container">
    <el-row :gutter="20">
    <!--部门数据-->
    <el-col :span="4" :xs="24">
      <div class="head-container">
        <el-tree
          :data="studentData"
          :expand-on-click-node="false"
          ref="tree"
          default-expand-all
          @node-click="handleNodeClick"
        />
      </div>
    </el-col>
    <!--知识点信息-->
    <el-col :span="20" :xs="24">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="目录编号" prop="knowledgeListId" v-if="false">
        <el-input
          v-model="queryParams.knowledgeListId"
          placeholder="目录编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年级" prop="grade">
        <el-select v-model="queryParams.grade" placeholder="请选择年级" clearable size="small">
          <el-option
            v-for="dict in gradeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="科目" prop="subject" v-if="false">
        <el-select v-model="queryParams.subject" placeholder="请选择科目" clearable size="small">
          <el-option
            v-for="dict in subjectOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="单元(章)" prop="unit" v-if="false">
        <el-input
          v-model="queryParams.unit"
          placeholder="请输入单元(章)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上下册" prop="volume" v-if="false">
        <el-select v-model="queryParams.volume" placeholder="请选择上下册" clearable size="small">
          <el-option
            v-for="dict in volumeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="第几节" prop="pitchNumber" v-if="false">
        <el-input
          v-model="queryParams.pitchNumber"
          placeholder="请输入第几节"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="视频" prop="videoUrl" v-if="false">
        <el-input
          v-model="queryParams.videoUrl"
          placeholder="请输入视频"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="难度" prop="diffictRatio" v-if="false">
        <el-input
          v-model="queryParams.diffictRatio"
          placeholder="请输入难度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="重要性" prop="importRatio" v-if="false">
        <el-input
          v-model="queryParams.importRatio"
          placeholder="请输入重要性"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="基础分值" prop="baseRatio" v-if="false">
        <el-input
          v-model="queryParams.baseRatio"
          placeholder="请输入基础分值"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="得分" prop="knowledgeScore" v-if="false">
        <el-input
          v-model="queryParams.knowledgeScore"
          placeholder="请输入知识点得分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="例题个数" prop="exampleSubjectNumber" v-if="false">
        <el-input
          v-model="queryParams.exampleSubjectNumber"
          placeholder="请输入知识点例题个数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择处理状态" clearable size="small">
          <el-option
            v-for="dict in auditStatus"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="删除状态" prop="isDel" v-if="false">
        <el-select v-model="queryParams.isDel" placeholder="请选择处理状态" clearable size="small">
          <el-option
            v-for="dict in deleteStatus"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-if="false"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['receipt:knowledgeManagerAudit:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="managerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" v-if="false"/>
      <el-table-column label="知识点目录编号" align="center" prop="knowledgeListId" v-if="false"/>
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="年级" align="center" prop="grade" :formatter="gradeFormat" />
      <el-table-column label="科目" align="center" prop="subject" :formatter="subjectFormat" />
      <el-table-column label="单元(章)" align="center" prop="unit" v-if="false"/>
      <el-table-column label="上下册" align="center" prop="volume" :formatter="volumeFormat" v-if="false"/>
      <el-table-column label="第几节" align="center" prop="pitchNumber" v-if="false"/>
      <el-table-column label="视频" align="center" prop="videoUrl" v-if="false"/>
      <el-table-column label="难度" align="center" prop="diffictRatio" v-if="false"/>
      <el-table-column label="重要性" align="center" prop="importRatio" v-if="false"/>
      <el-table-column label="基础分值" align="center" prop="baseRatio" v-if="false"/>
      <el-table-column label="得分" align="center" prop="knowledgeScore" v-if="false" />
      <el-table-column label="例题个数" align="center" prop="exampleSubjectNumber" v-if="false"/>
      <el-table-column label="审核状态" align="center" prop="status" :formatter="auditStatusFormat"/>
      <el-table-column label="删除状态" align="center" prop="isDel" v-if="false"/>
      <el-table-column label="审核意见" align="center" prop="remark" v-if="false"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="approvedAudit(scope.row,'2')"
            v-if="isPassButtonShow(scope.row,'pass')"
            v-hasPermi="['receipt:knowledgeManager:pass']"
          >通过</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="approvedAudit(scope.row,'3')"
            v-if="isBackButtonShow(scope.row,'back')"
            v-hasPermi="['receipt:knowledgeManagerAudit:back']"
          >驳回</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="approvedAudit(scope.row,'1')"
            v-if="isUpadateButtonShow(scope.row,'update')"
            v-hasPermi="['receipt:knowledgeManagerAudit:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="approvedAudit(scope.row,'4')"
            v-if="isShowLookButton(scope.row)"
            v-hasPermi="['receipt:knowledgeManagerAudit:check']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-col>
    </el-row>

    <!-- 添加或修改知识点管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <div id = "knowledgeDialogDiv" v-show="isShowKnowledgeDialogDiv">
        <el-form-item label="目录编号" prop="knowledgeListId" v-if="false">
          <el-input v-model="form.knowledgeListId" placeholder="请输入目录编号" />
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="单元(章)" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单元(章)" />
        </el-form-item>
        <el-form-item label="第几节" prop="pitchNumber">
          <el-input v-model="form.pitchNumber" placeholder="请输入第几节" />
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-select v-model="form.grade" placeholder="请选择年级" >
            <el-option
              v-for="dict in gradeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="科目" prop="subject">
          <el-select v-model="form.subject" placeholder="请选择科目" >
            <el-option
              v-for="dict in subjectOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上下册" prop="volume">
          <el-select v-model="form.volume" placeholder="请选择上下册" >
            <el-option
              v-for="dict in volumeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="视频" prop="videoUrl">
          <el-upload class="avatar-uploader"
                     action="http://localhost:8080/reception/upload/"
                     v-bind:on-progress="uploadVideoProcess"
                     v-bind:on-success="handleVideoSuccess"
                     v-bind:before-upload="beforeUploadVideo"
                     v-bind:show-file-list="false">
            <video v-if="form.videoUrl !='' && !videoFlag" style="width: 500px;height: 200px;"
                   v-bind:src="form.videoUrl"
                   class="avatar video-avatar"
                   controls="controls">
              您的浏览器不支持视频播放
            </video>
            <i v-else-if="form.videoUrl =='' && !videoFlag"
               class="el-icon-plus avatar-uploader-icon"></i>
            <el-progress v-if="videoFlag == true"
                         type="circle"
                         v-bind:percentage="videoUploadPercent"
                         style="margin-top:7px;"></el-progress>
          </el-upload>
        </el-form-item>
        <el-form-item label="教案" prop="teachingPlanContent" >
          <!-- 图片上传组件辅助 -->
          <el-upload
            class="avatar-uploader quill-img"
            :action="serverUrl"
            name="file"
            :show-file-list="false"
            :on-success="quillImgSuccess"
            :on-error="uploadError"
            :before-upload="quillImgBefore"
            accept='.jpg,.jpeg,.png,.gif,.avi,.mp4'
          ></el-upload>
          <!-- 富文本组件 -->
          <quillEditor
            class="editor"
            v-model="content"
            ref="quillEditor"
            :options="editorOption"
            @blur="onEditorBlur($event)"
            @focus="onEditorFocus($event)"
            @change="onEditorChange($event)"
            :class="editorClass"
          ></quillEditor>
        </el-form-item>
        <el-form-item label="难度" prop="diffictRatio">
          <el-input v-model="form.diffictRatio" placeholder="请输入难度" @input="countTotalArea()" />
        </el-form-item>
        <el-form-item label="重要性" prop="importRatio">
          <el-input v-model="form.importRatio" placeholder="请输入重要性" @input="countTotalArea()" />
        </el-form-item>
        <el-form-item label="基础分值" prop="baseRatio">
          <el-input v-model="form.baseRatio" placeholder="请输入基础分值" @input="countTotalArea()" />
        </el-form-item>
        <el-form-item label="得分" prop="knowledgeScore" v-if="false">
          <el-input v-model="form.knowledgeScore" placeholder="请输入知识点得分(根据难度+重要性+基础分值得出)" @change="scoreChange()" />
        </el-form-item>
        <el-form-item label="例题个数" prop="exampleSubjectNumber">
          <el-input v-model="form.exampleSubjectNumber" placeholder="请输入知识点例题个数,默认5道" />
        </el-form-item>
        <el-form-item label="处理状态" prop="status" v-if="false">
          <el-select v-model="form.status" placeholder="请选择处理状态">
            <el-option
              v-for="dict in auditStatus"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="删除状态" prop="status" v-if="false">
          <el-select v-model="form.isDel" placeholder="请选择处理状态">
            <el-option
              v-for="dict in deleteStatus"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        </div>
        <el-form-item label="审核意见" prop="remark" v-if="isShowAuditItem">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入审核意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" id="buttonDiv" v-show="isShowButtonDiv">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<style scoped>
>>> .ql-editor{ height:150px; }
</style>
<script>
    // 工具栏配置
    const toolbarOptions = [
        ["bold", "italic", "underline", "strike"], // toggled buttons
        ["blockquote", "code-block"],

        [{ header: 1 }, { header: 2 }], // custom button values
        [{ list: "ordered" }, { list: "bullet" }],
        [{ script: "sub" }, { script: "super" }], // superscript/subscript
        [{ indent: "-1" }, { indent: "+1" }], // outdent/indent
        [{ direction: "rtl" }], // text direction

        [{ size: ["small", false, "large", "huge"] }], // custom dropdown
        [{ header: [1, 2, 3, 4, 5, 6, false] }],

        [{ color: [] }, { background: [] }], // dropdown with defaults from theme
        [{ font: [] }],
        [{ align: [] }],
        ["link", "image"],
        ["clean"] // remove formatting button
    ];
import { listManager, getManager, delManager, addManager, updateManager, exportManager, getTreeData,exportManagerAudit } from "@/api/knowledge/knowledgeManager";
import { getPlanByManagerId } from "@/api/knowledge/knowledgeTeach";
import quillEditor from "vue-quill-editor";
export default {
    props: {
        /* 编辑器的内容 */
        value: {
            type: String
        },
        editorClass: {
            type: String,
            default: ""
        },
        /* 图片大小 */
        maxSize: {
            type: Number,
            default: 4000 //kb
        }
    },
  name: "Manager",
  components:
      quillEditor,
  data() {
    var diffictRatio = (rule, value, callback) => {
        if(value > 100){
            return callback(new Error('难度不能大于100'));
        }else if(value <= 0){
            return callback(new Error('难度不能小于1'));
        }else if(Number(value)+'' == 'NaN'){
            return callback(new Error('难度个数必须为数字'));
        }else{
            callback();
        }
    };
    var importRatio = (rule, value, callback) => {
        if(value > 100){
            return callback(new Error('重要性不能大于100'));
        }else if(value <= 0){
            return callback(new Error('重要性不能小于1'));
        }else if(Number(value)+'' == 'NaN'){
            return callback(new Error('重要性必须为数字'));
        }else{
            callback();
        }
    };
    var baseRatio = (rule, value, callback) => {
        if(value > 1000){
            return callback(new Error('基础分值不能大于1000'));
        }else if(value <= 0){
            return callback(new Error('基础分值不能小于1'));
        }else if(Number(value)+'' == 'NaN'){
            return callback(new Error('基础分值个数必须为数字'));
        }else{
            callback();
        }
    };
    var exampleSubjectNumber = (rule, value, callback) => {
        if(value > 20){
            return callback(new Error('例题个数不能大于20'));
        }else if(value <= 0){
            return callback(new Error('例题个数不能小于1'));
        }else if(Number(value)+'' == 'NaN'){
            return callback(new Error('例题个数必须为数字'));
        }else{
            callback();
        }
    };
    var unitValidator = (rule, value, callback) => {
        if(Number(value)+'' == 'NaN'){
            return callback(new Error('单元(章)必须为数字'));
        }else{
            callback();
        }
    };
    var pitchNumberValidator = (rule, value, callback) => {
        if(Number(value)+'' == 'NaN'){
            return callback(new Error('第几节必须为数字'));
        }else{
            callback();
        }
    };
      var teachingPlanContent = (rule, value, callback) => {
          const reg = /<\/?.+?\/?>/g;
          var length = this.$refs.quillEditor.quill.root.innerHTML.replace(reg, '').length;
          var lengthLong = this.$refs.quillEditor.quill.root.innerHTML.length;
          if(length <= 0){
              if (lengthLong > 11){
                  callback();
              }
              return callback(new Error('教案内容不能为空'));
          }else{
              callback();
          }
      };
    return {
      quill: null,
      isShowButtonDiv: true,
      isShowKnowledgeDialogDiv: true,
      studentData: [],
      isShowAuditItem: true,
      videoFlag: false,
      //是否显示进度条
      videoUploadPercent: "",
      //进度条的进度，
      isShowUploadVideo: false,
      content: this.value,
      header: { token: sessionStorage.token }, // 有的图片服务器要求请求头需要有token之类的参数，写在这里
      // 遮罩层
      loading: true,
      serverUrl: "http://localhost:8080/reception/upload", // 这里写你要上传的图片服务器地址
      ossUrl: "",
      editorOption: {
            placeholder: "",
            theme: "snow", // or 'bubble'
            modules: {
                toolbar: {
                    container: toolbarOptions, // 工具栏
                    handlers: {
                        image: function(value) {
                            if (value) {
                                document.querySelector(".quill-img input").click();
                            } else {
                                this.quill.format("image", false);
                            }
                        }
                    }
                }
            }
      },
      knowledgeListId: "",
      fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 知识点管理表格数据
      managerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 年级->dict_grade字典
      gradeOptions: [],
      //审核状态字典
      auditStatus: [],
      //删除状态字典
      deleteStatus: [],
      // 科目->dict_subject字典
      subjectOptions: [],
      // 上下册->dict_volume字典
      volumeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        knowledgeListId: null,
        title: null,
        grade: null,
        subject: null,
        unit: null,
        volume: null,
        pitchNumber: null,
        videoUrl: null,
        diffictRatio: null,
        importRatio: null,
        baseRatio: null,
        knowledgeScore: null,
        exampleSubjectNumber: null,
        status: null,
        isDel: null,
        treeListId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
          // 表单校验
          title:[
              { required: true, //是否必填
                  message: '标题不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
              //可以设置双重验证标准
              { min: 2, max: 25,  message: '长度在 2 到 25 个字符', }
          ],
          unit:[
              { required: true, //是否必填
                  message: '单元不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
              { validator: unitValidator, trigger: 'blur' },
          ],
          pitchNumber:[
              { required: true, //是否必填
                  message: '第几节不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
              { validator: pitchNumberValidator, trigger: 'blur' }
          ],
          grade:[
              { required: true, //是否必填
                  message: '年级不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
          ],
          subject:[
              { required: true, //是否必填
                  message: '科目不能为空', //规则
                  trigger: 'blur'  //何事件触发
              }
          ],
          volume:[
              { required: true, //是否必填
                  message: '上下册不能为空', //规则
                  trigger: 'blur'  //何事件触发
              }
          ],
          diffictRatio:[
              { required: true, //是否必填
                  message: '难度不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
              { validator: diffictRatio, trigger: 'blur' },
          ],
          importRatio:[
              { required: true, //是否必填
                  message: '重要性不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
              { validator: importRatio, trigger: 'blur' },
          ],
          baseRatio:[
              { required: true, //是否必填
                  message: '基础分值不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
              { validator: baseRatio, trigger: 'blur' },
          ],
          exampleSubjectNumber:[
              { required: true, //是否必填
                  message: '例题个数不能为空', //规则
                  trigger: 'blur'  //何事件触发
              },
              { validator: exampleSubjectNumber, trigger: 'blur' },
          ],
          teachingPlanContent:[
              { validator: teachingPlanContent, trigger: 'blur' },
          ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("dict_grade").then(response => {
        this.gradeOptions = response.data;
    });
    this.getDicts("sys_audit_status").then(response => {
        this.auditStatus = response.data;
    });
    this.getDicts("sys_delete_status").then(response => {
        this.deleteStatus = response.data;
    });
    this.getDicts("dict_subject").then(response => {
      this.subjectOptions = response.data;
    });
    this.getDicts("dict_volume").then(response => {
      this.volumeOptions = response.data;
    });
    this.getTreeselect();
    //this.getUill();
  },
  watch: {
      value: function() {
          this.content = this.value;
      }
  },
  methods: {

    //上传前回调
    beforeUploadVideo(file) {
      var fileSize = file.size / 1024 / 1024 < 50;
      if (['video/mp4', 'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb', 'video/mov'].indexOf(file.type) == -1) {
        layer.msg("请上传正确的视频格式");
        return false;
      }
      if (!fileSize) {
        layer.msg("视频大小不能超过50MB");
        return false;
      }
      this.isShowUploadVideo = false;
    },
    //进度条
    uploadVideoProcess(event, file, fileList) {
      this.videoFlag = true;
      this.videoUploadPercent = file.percentage.toFixed(0) * 1;
    },
    //上传成功回调
    handleVideoSuccess(res, file) {
      this.isShowUploadVideo = true;
      this.videoFlag = false;
      this.videoUploadPercent = 0;

      this.form.videoUrl = res.data.cloudPath;

    },
    //判断是否显示确定按钮
    isShowDefineButton(){
        if (this.form.status == '1'){
            return true;
        }else {
            return false;
        }
    },
    //判断审核按钮是否显示
    isShowAuditButton(row){
        if (row.status == '1'){
            return true;
        }else {
            return false;
        }
    },
    //判断查看按钮是否显示
    isShowLookButton(row){
        return true;
    },
    //控制通过按钮的显示隐藏
    isPassButtonShow(row,rel){
        if (row.status == '1'){
            return true;
        }else {
            return false;
        }
    },
    //控制查看按钮的显示隐藏
    isLookButtonShow(row,rel){
        return true;
    },
    //控制编辑按钮的显示隐藏
    isUpadateButtonShow(row,rel){
        if (row.status != '1'){
            return false;
        }else {
            return true;
        }
    },
    //控制驳回按钮的显示隐藏
    isBackButtonShow(row,rel){
        if (row.status == '1'){
            return true;
        }else {
            return false;
        }
    },
    getUill(){
        let quill = this.$refs.quillEditor.quill;
        this.quill = quill;
    },
    //富文本相关方法
    onEditorBlur() {
        //失去焦点事件
    },
    onEditorFocus() {
        //获得焦点事件
    },
    onEditorChange() {
        //内容改变事件
        this.$emit("input", this.content);
    },
    // 富文本图片上传前
    quillImgBefore(file) {
        let fileType = file.type;
        this.fileType = fileType;
        //判断文件是图片还是视频或者其他格式文档
        if (fileType.indexOf('image') != -1){
            if(fileType === 'image/jpeg' || fileType === 'image/png'){
                return true;
            }else {
                this.$message.error('请插入图片类型文件(jpg/jpeg/png)');
                return false;
            }
        }else if(fileType.indexOf('video') != -1){
            if(fileType === 'video/avi' || fileType === 'video/mp4'){
                return true;
            }else {
                this.$message.error('请插入视频类型文件(avi/mp4)');
                return false;
            }
        }
    },
    quillImgSuccess(res, file) {
        // res为图片服务器返回的数据
        // 获取富文本组件实例
        let quill = this.$refs.quillEditor.quill;
        // 如果上传成功
        if (res.code == 200) {
            // 获取光标所在位置
            let length = quill.getSelection().index;
            if (this.fileType.indexOf('image') != -1){
                // 插入图片  res.url为服务器返回的图片地址
                quill.insertEmbed(length, "image", res.data.cloudPath);
            }else if (this.fileType.indexOf('video') != -1){
                // 插入图片  res.url为服务器返回的图片地址
                quill.insertEmbed(length, "video", res.data.cloudPath);
            }
            // 调整光标到最后
            quill.setSelection(length + 1);
        } else {
            this.$message.error("图片插入失败...");
        }
    },
    // 富文本图片上传失败
    uploadError() {
        // loading动画消失
        this.quillUpdateImg = false;
        this.$message.error("图片插入失败");
    },
    handleRemove(file, fileList) {
    },
    handlePreview(file) {
    },
    handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
    },
    uploadSuccess(response, file, fileList){
        this.ossUrl = response.data.cloudPath;
    },
    // 节点单击事件
    handleNodeClick(data) {
        this.queryParams.knowledgeListId = data.id;
        this.knowledgeListId = data.id;
        this.getList();
    },
    /** 查询知识点管理列表 */
    getList() {
      this.loading = true;
      //这里查询所有未删除的知识点列表
      this.queryParams.isDel = '0';
      listManager(this.queryParams).then(response => {
        this.managerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //根据input框change事件动态获取知识点得分
    countTotalArea(){
      this.form.knowledgeScore = this.form.importRatio*1 + this.form.diffictRatio*1 + this.form.baseRatio*1;
  },
    /** 查询部门下拉树结构 */
    getTreeselect() {
        getTreeData(this.queryParams).then(response => {
            this.studentData = eval(JSON.stringify(response));
        });
        //let studentData = eval(str);
    },
    // 年级->dict_grade字典翻译
    gradeFormat(row, column) {
      return this.selectDictLabel(this.gradeOptions, row.grade);
    },
    // 科目->dict_subject字典翻译
    subjectFormat(row, column) {
      return this.selectDictLabel(this.subjectOptions, row.subject);
    },
    // 上下册->dict_volume字典翻译
    volumeFormat(row, column) {
      return this.selectDictLabel(this.volumeOptions, row.volume);
    },
    //审核状态字典翻译
    auditStatusFormat(row, column) {
        return this.selectDictLabel(this.auditStatus, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.ossUrl = "",
      this.fileList = [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}],
      this.form = {
        id: null,
        knowledgeListId: null,
        teachingPlanContent: "",
        title: null,
        grade: null,
        subject: null,
        unit: null,
        volume: null,
        pitchNumber: null,
        videoUrl: null,
        diffictRatio: 30,
        importRatio:  30,
        baseRatio: 300,
        knowledgeScore: 360,
        exampleSubjectNumber: 5,
        status: 1,
        isDel: 0,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.knowledgeListId = "";
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      // 获取富文本组件实例
      this.form.knowledgeListId = this.knowledgeListId;
    },
    //通过审核
    approvedAudit(row,status){
        this.reset();
        const id = row.id || this.ids
        //获取知识点信息
        getManager(id).then(response => {
            this.form = response.data;
            this.form.status = status;
            let url = '{'+"name:"+"aaa.avi"+","+"url:"+response.data.videoUrl+'}';
            this.fileList.push(`{"name:"+"aaa.avi"+","+"url:"+response.data.videoUrl+'}`);
        });
        //获取知识点教案信息
        getPlanByManagerId(id).then(response => {
            // 获取富文本组件实例
            var str = JSON.stringify(response);
            let quill = this.$refs.quillEditor.quill;
            if(str.indexOf("content") != -1){
                quill.root.innerHTML = response.data.content;
                this.form.teachingPlanContent = response.data.content;
            }else{
                quill.root.innerHTML = "";
                this.form.teachingPlanContent = "";
            }
        });
        //修改按钮
        if (status == '1'){
            this.isShowAuditItem = false;
            this.isShowKnowledgeDialogDiv = true;
            this.isShowButtonDiv = true;
            this.title = "修改知识点";
        //通过按钮
        }else if (status == '2'){
            this.isShowAuditItem = true;
            this.isShowKnowledgeDialogDiv = false;
            this.isShowButtonDiv = true;
            this.title = "通过知识点审核";
        //驳回按钮
        }else if (status == '3'){
            this.isShowAuditItem = true;
            this.isShowKnowledgeDialogDiv = false;
            this.isShowButtonDiv = true;
            this.title = "知识点审核驳回";
        //查看按钮
        }else if (status == '4'){
            this.isShowAuditItem = true;
            this.isShowKnowledgeDialogDiv = true;
            this.isShowButtonDiv = false;
            this.title = "查看知识点详情";
        }
        this.open = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            if (this.form.id != null) {
              // 获取富文本组件实例
              let quill = this.$refs.quillEditor.quill;
              this.form.teachingPlanContent = quill.root.innerHTML;
              updateManager(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            }
          }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除知识点管理编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delManager(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有知识点管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportManagerAudit(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
